/**
 * @ Author: luoqi
 * @ Create Time: 2025-02-28 23:00
 * @ Modified by: luoqi
 * @ Modified time: 2025-03-13 22:45
 * @ Description:
 */

#include "focd.h"

int focd_init(FocDebugger *dbg, qfp_t fs, qfp_t frq, DumpFunc dump)
{
    if(!dbg || !dump) {
        return -1;
    }

    dbg->dump = dump;
    dbg->ena = FOCD_OFF;
    dbg->is_dump = FOCD_DUMP_ON;
    qwave_init(&dbg->wave, QWAVE_TYPE_SINE, fs, frq, 0, 0);

    return 0;
}

int focd_ena_set(FocDebugger *dbg, FocdEna ena)
{
    if(!dbg) {
        return -1;
    }
    dbg->ena = ena;
    qwave_clr(&dbg->wave);
    return 0;
}

int focd_signal_set(FocDebugger *dbg, QWaveType type)
{
    if(!dbg) {
        return -1;
    }
    dbg->ena = FOCD_OFF;
    qwave_signal_set(&dbg->wave, type);
    return 0;
}

int focd_amp_set(FocDebugger *dbg, qfp_t amp)
{
    if(!dbg) {
        return -1;
    }
    qwave_amp_set(&dbg->wave, amp);

    return 0;
}

int focd_frq_set(FocDebugger *dbg, qfp_t frq)
{
    if(!dbg) {
        return -1;
    }
    qwave_frq_set(&dbg->wave, frq);
    return 0;
}

int focd_fs_set(FocDebugger *dbg, qfp_t fs)
{
    if(!dbg) {
        return -1;
    }
    qwave_fs_set(&dbg->wave, fs);
    return 0;
}

int focd_dump(FocDebugger *dbg, const uint8_t *data, uint32_t len)
{
    if(!dbg || !dbg->dump) {
        return -1;
    }
    if((dbg->ena == FOCD_OFF) || (dbg->is_dump == FOCD_DUMP_OFF)) {
        return 0;
    }
    return dbg->dump(data, len);
}

int focd_signal_output(FocDebugger *dbg, qfp_t *output)
{
    if(!dbg || !output) {
        return -1;
    }

    if((dbg->ena == FOCD_OFF)) {
        return 0;
    }

    *output = qwave_signal_output(&dbg->wave);

    return 1;
}
